<?php
/**
 * 
 */
use Doctrine\DBAL\Connection;
use Fox\Common\Customer;
$ajax = Xview::instance()->val("xvtrs");
$blCompetitors = Xview::instance()->component("inquiry", "competitors"); 
$grid = $blCompetitors->item("gCompetitors");
if(!empty($ajax))
{
	$uniqueData = null;
	$data = $grid->get(null,true);
	if(is_array($data))
	{
		foreach($data as $key => $line)
		{
			if(empty($line['customerid']))
				continue;
			$uniqueData[$line['customerid']] = $line;
		}
	}
	$partnersCode = Xview::instance()->val("partnersCode");
	if(is_array($partnersCode))
	{
		$finder = new Customer();
		$customers = $finder->find(new Fox\Dao\SqlFragment("customerid IN (?)",array($partnersCode),array(Connection::PARAM_INT_ARRAY)));
		foreach($customers as $customer)
		{
			$data['name1'] = $customer->name1;
			$data['customerid'] = $customer->getId();
			$uniqueData[$customer->getId()] = $data;
		}
	}
	$grid->setDatas($uniqueData);
	echo $grid->Display();
}
